package org.erepublik.company.service;

import org.erepublik.company.ECountry;
import org.erepublik.company.EProductType;
import org.erepublik.company.Job;
import org.erepublik.company.product.Food;
import org.erepublik.company.product.House;
import org.erepublik.company.product.ProductDesign;
import org.erepublik.company.product.Raw;
import org.erepublik.company.product.Ticket;
import org.erepublik.company.product.Weapons;

/**
 * Klasa dostarczajaca oferty jedzenia z plikow JSON.
 * 
 * Obiekt sprawdza, czy nie ma nowszych ofert i zawsze zwraca najbardziej aktualne oferty
 *
 * @author Kacper Gorski 'Railman' railman85@gmail.com
 */
public class JSONProductsService implements IProductsService {

    private JSONRawService rawService = new JSONRawService();
    private JSONFoodService foodService = new JSONFoodService();
    private JSONTicketService ticketService = new JSONTicketService();
    private JSONHouseService houseService = new JSONHouseService();
    private JSONJobService jobService = new JSONJobService();
    
    private JSONWeaponService tankService = new JSONWeaponService(EProductType.TANK, "tank");
    private JSONWeaponService rifleService = new JSONWeaponService(EProductType.RIFLE, "rifle");
    private JSONWeaponService artService = new JSONWeaponService(EProductType.ARTILLERY, "artillery");
    private JSONWeaponService heliService = new JSONWeaponService(EProductType.HELICOPTER, "helicopter");

    @Override
    public String getMinutesSinceRawUpdate() {
        return rawService.getMinutesSinceUpdate();
    }
    @Override
    public String getMinutesSinceFoodUpdate() {
        return foodService.getMinutesSinceFoodUpdate();
    }
    @Override
    public String getMinutesSinceHouseUpdate() {
        return houseService.getMinutesSinceHouseUpdate();
    }
    @Override
    public String getMinutesSinceTicketUpdate() {
        return ticketService.getMinutesSinceTicketUpdate();
    }
    @Override
    public String getMinutesSinceJobUpdate() {
        return jobService.getMinutesSinceUpdate();
    }

    


    
    
    @Override
    public House[] getHouses(ECountry country) {
        return houseService.getHouses(country);
    }
    @Override
    public Food[] getFood(ECountry country) {
        return foodService.getFood(country);
    }
    @Override
    public Ticket[] getTickets(ECountry country, int distance) {
        return ticketService.getTickets(country, distance);
    }
    @Override
    public Raw[] getRaws(ECountry country, EProductType productType) {
        return rawService.getRaws(country, productType);
    } 
    @Override
    public Job[] getJobs(ECountry country,  int minimalSkill) {
        return jobService.getJobs(country,  minimalSkill);
    }
    

    public String getMinutesSinceWeaponUpdate(EProductType product) {
        if (product == EProductType.TANK)
            return tankService.getMinutesSinceUpdate();
        if (product == EProductType.RIFLE)
            return rifleService.getMinutesSinceUpdate();
        if (product == EProductType.HELICOPTER)
            return heliService.getMinutesSinceUpdate();
        if (product == EProductType.ARTILLERY)
            return artService.getMinutesSinceUpdate();
        
        return null;
    }
    public Weapons[] getWeapons(ECountry country, ProductDesign minimalDesign, EProductType product) {
        if (product == EProductType.TANK)
            return tankService.getWeapons(country, minimalDesign);
        if (product == EProductType.RIFLE)
            return rifleService.getWeapons(country, minimalDesign);
        if (product == EProductType.HELICOPTER)
            return heliService.getWeapons(country, minimalDesign);
        if (product == EProductType.ARTILLERY)
            return artService.getWeapons(country, minimalDesign);
        
        return null;
    }




}
